package pl.makimo.data;

import java.io.IOException;
import java.util.ArrayList;

import pl.makimo.fuzzy.sets.CrispSet;

import com.csvreader.CsvReader;

public class WeatherRecord extends Record {
	public Double time;
	public Double temperature;
	public Double dew;
	public Double humidity;
	public Double pressure;
	public Double visibility;
	public String wind_direction;
	public Double wind_speed;
	public Double gust_speed;
	public String precipitation;
	public String events;
	public String conditions;
	public Double wind_dir;
	
	@Override
	public Object get(String label) {
		if (label.equals("time")) return this.time;
		if (label.equals("temperature")) return this.temperature;
		if (label.equals("dew")) return this.dew;
		if (label.equals("humidity")) return this.humidity;
		if (label.equals("pressure")) return this.pressure;
		if (label.equals("visibility")) return this.visibility;
		if (label.equals("wind direction")) return this.wind_direction;
		if (label.equals("wind speed")) return this.wind_speed;
		if (label.equals("gust speed")) return this.gust_speed;
		if (label.equals("precipitation")) return this.precipitation;
		if (label.equals("events")) return this.events;
		if (label.equals("conditions")) return this.conditions;
		if (label.equals("wind_dir")) return this.wind_dir;
		
		return null;
	}
	
	public static CrispSet<WeatherRecord> getFromFile(String filename) {
		try {
			CrispSet<WeatherRecord> list = new CrispSet<WeatherRecord>();
			
			CsvReader csv = new CsvReader(filename, ',');
			
			int i = 0;
			
			while (csv.readRecord() == true) {
				String[] values = csv.getValues();
				
				try {
					WeatherRecord record = new WeatherRecord();
					record.time =Double.parseDouble(values[0]);
					record.temperature = Double.parseDouble(values[1]);
					record.dew = Double.parseDouble(values[2]);
					record.humidity = Double.parseDouble(values[3]);
					record.pressure = Double.parseDouble(values[4]);
					record.visibility = Double.parseDouble(values[5]);
					record.wind_direction = values[6];
					record.wind_speed = Double.parseDouble(values[7]);
					// record.gust_speed = Double.parseDouble(values[8]);
					record.precipitation = values[9];
					record.events = values[10];
					record.conditions = values[11];
					record.wind_dir = Double.parseDouble(values[12]);
					list.add(record);
				} catch (Exception e) {
					continue;
				}
			}
			
			return list;
		} catch (IOException e) {
			return new CrispSet<WeatherRecord>();
		}
	}
}
